package z.t.b.db.utils;

import java.math.BigInteger;

/**
 * @author ：ztb
 * @date ：Created in 2024/3/22 15:35
 * @description：
 * @modified By：ztb
 * @version: 1.0
 */
public class StrUtils {

    /**
     * 清除单引号
     * @param str
     * @return
     */
    public static String clearSQuotes(String str){
        return str.replace("`","");
    }

    public static String clearEngine(String str){
        return str.replaceAll(" ENGINE=[^\\s]+", "");
    }

    public static String clearCharset(String str){
        return str.replaceAll(" DEFAULT CHARSET=[^\\s]+", "");
    }

    public static String clearCharacterCollate(String str){
        return str.replaceAll(" CHARACTER SET [^\\s]+ COLLATE [^\\s]+", "");
    }

    public static String clearCollate(String str){
        return str.replaceAll(" COLLATE=[^\\s]+", "");
    }

    public static String clearAlgorithm(String str){
        return str.replaceAll("ALGORITHM=[^\\s]+", "");
    }

    public static String clearDefiner(String str){
        return str.replaceAll("DEFINER=[^\\s]+", "");
    }

    public static String clearSqlSecurityDefiner(String str){
        return str.replaceAll("SQL SECURITY DEFINER", "");
    }

    /**
     * 字符串单引号引起来
     * @param s
     * @return
     */
    public static String getDbString(String s) {
        return "'" + s + "'";
    }

    /**
     * 流转16进制字符串
     * @param bytes
     * @return
     */
    public static String bytesToHex(byte[] bytes) {
        BigInteger bigInteger = new BigInteger(1, bytes);
        return String.format("%0" + (bytes.length << 1) + "X", bigInteger);
    }
}
